package admin.core.ui;

import admin.core.service.IService;

import javax.swing.*;
import java.lang.reflect.Constructor;

public class SwingApplication {
    public static void run(Class<?> service) {
        SwingUtilities.invokeLater(
                () -> {
                    new GenericTableFrame<>(createService(service));
                }
        );
    }

    private static IService<?> createService(Class<?> clazz) {
        Constructor<?> constructor = null;
        IService<?> instance = null;
        try {
            constructor = clazz.getDeclaredConstructor();
            instance = (IService<?>) constructor.newInstance();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return instance;
    }
}
